const express = require('express');

const router = express.Router();

router.all('/login', (req, res) => {
    if (req.method.toUpperCase() !== 'POST') {
        return res.json({
            msg: '请求类型错误',
            code: '001'
        })
    }

    //判断
    if (!req.body.username || !req.body.password) {
        return res.json({
            msg: '用户名或密码不能为空',
            code: '002'
        })

    }
    if (req.body.username !== 'admin' || req.body.password !== 'admin') {
        return res.json({
            msg: '登录失败!! 用户名或密码错误',
            code: '003'
        })
    }

    res.json({
        code: '000',
        msg: '登录成功'
    });
});

module.exports = router;